package com.yezong.AidMe.service;

import com.yezong.AidMe.entity.Order;
import com.yezong.AidMe.entity.User;
import com.yezong.AidMe.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Logger;

@Component
@Service
public class OrderService {

    Logger logger = Logger.getLogger("OrderService");

    private static OrderService orderService;

    @Autowired
    private OrderMapper orderMapper;

    public String locate(String location) {
        return location.split("市")[0];
    }

    public List<Order> unionList(List<Order> l1, List<Order> l2){
        int i=0,j=0;
        List list = null;
        while (l1.get(i)!=null || l2.get(j)!=null){
            if (l1.get(i) == null){
                list.add(l1.get(i));
                i++;
            }
            else if (l2.get(j) == null){
                list.add(l2.get(j));
                j++;
            }
            else{
                list.add(l1.get(i));
                list.add(l2.get(j));
                i++;
                j++;
            }
        }
        for (Object item : list){
            System.out.println(item.toString());
        }
        return list;
    }

    public Order searchById(Integer id) {return orderMapper.selectById(id);}

    public List<Order> searchByTitleAndDetails(String word) {return orderMapper.selectByTitleAndDetails(word);}

    public List<Order> searchByView() {return orderMapper.selectByView();}

    public List<Order> searchByPublishTime() {return orderMapper.selectByPublishTime();}

    public List<Order> searchByLocalView(String location) {return orderMapper.selectByLocalView(location);}

    public List<Order> searchByLocalPublishTime(String location) {return orderMapper.selectByLocalPublishTime(location);}

    public List<Order> searchByType(String type) {return orderMapper.selectByType(type);}

    public Boolean insertOrder(Order order) {return orderMapper.insertOrder(order) > 0;}

    public Boolean updateOrder(Order order, Integer id) {return orderMapper.updateOrder(order, id) > 0;}

    public Boolean deleteOrder(Integer id) {return orderMapper.deleteOrder(id) > 0;}

    public List<Order> searchAll() {return orderMapper.selectAll();}
}
